# Copyright (c) Meta Platforms, Inc. and affiliates.

load("@fbcode_macros//build_defs:protobuf_library.bzl", "protobuf_library")
load("../../../defs.bzl", "zs_cxxlibrary", "zs_fuzzers", "zs_unittest")

oncall("data_compression")

zs_cxxlibrary(
    name = "utils",
    srcs = ["utils.cpp"],
    headers = ["utils.h"],
    preprocessor_flags = [
        "-DOPENZL_BUCK_BUILD",
    ],
    exported_deps = ["fbsource//xplat/tools/cxx:resources"],
)

zs_unittest(
    name = "test_proto_serializer",
    srcs = ["test_proto_serializer.cpp"],
    compiler_flags = [
        "-Wno-switch-enum",
        "-Wno-cast-qual",
    ],
    deps = [
        "..:serializer",
        "../../..:zstronglib",
        ":test_schema-cpp",
    ],
    external_deps = ["protobuf"],
)

zs_unittest(
    name = "test_proto_utils",
    srcs = ["test_proto_utils.cpp"],
    deps = [
        "..:utils",
    ],
)

zs_unittest(
    name = "test_descriptor_loader",
    srcs = ["test_descriptor_loader.cpp"],
    preprocessor_flags = [
        "-DOPENZL_BUCK_BUILD",
    ],
    resources = glob(["resources/*"]),
    deps = [
        "..:utils",
        ":utils",
    ],
)

zs_unittest(
    name = "test_dynamic_messages",
    srcs = ["test_dynamic_messages.cpp"],
    preprocessor_flags = [
        "-DOPENZL_BUCK_BUILD",
    ],
    resources = glob(["resources/*"]),
    deps = [
        "..:utils",
        ":utils",
    ],
)

protobuf_library(
    name = "test_schema",
    srcs = ["test_schema.proto"],
    base_path = "data_compression/experimental/zstrong/tools/protobuf/tests",
    langs = [
        "cpp",
    ],
)

zs_fuzzers(
    srcs = [
        "fuzz_protobuf_serializer.cpp",
    ],
    ftest_names = [
        ("ProtobufSerializerTest", "FuzzRandomInput"),
    ],
    deps = [
        "..:serializer",
        "../../..:zstronglib",
        "fbsource//third-party/protobuf:libprotobuf",
        "fbsource//xplat/security/lionhead/utils/lib_ftest:lib",
        ":test_schema-cpp",
    ],
)
